#!/bin/zsh
# XXX: It's _ZSH_ !
# vim: ts=8 sw=4 sts=4 et

sufx="${RANDOM}"

declare -i UPLIM=${1:-100}
declare -i MAX_N=${2:-23}

for n in `seq ${3:-1} $MAX_N`; do
    REGEXP=`python2 -c "import hw1; print hw1.multiples($n)"`
    R_file="/tmp/$0-$n-regexp-$sufx"
    S_file="/tmp/$0-$n-str-$sufx"
    echo "$REGEXP" > "$R_file"

    typeset -i 2 i="${4:-0}"
    while [[ $(($i)) -lt $UPLIM ]]; do
        str="${i/2#/}"

        #echo "$str" | grep -q -E -e "$REGEXP" - # "argument list too long: grep"  *sigh*
        echo "$str" > "$S_file"

        grep -q -E -f "$R_file" "$S_file"
        if [ "$?" = "0" ]; then
            printf "%s: regexp for %s \033[01;32mmatches\033[00m '%s'\n" "$(($i))" "$n" "$str" # copy-paste programming ftw
        else
            printf "%s: regexp for %s \033[01;31mdoes not match\033[00m '%s'\n" "$(($i))" "$n" "$str"
        fi

        i=$(( $i + 1 ))
    done

    rm "$R_file" "$S_file"
done

echo "see ya"
